#{extends 'common/myHeader.html' /}
#{set title:'${model.comment}' /}
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form">
			<div class="layui-inline">
#foreach( $field in $fieldList )
#if(${field.matchType}=="any"||${field.matchType}=="eq"||${field.matchType}=="left"||${field.matchType}=="right")
				<span class="search_title">${field.comment}：</span>
		        <div class="layui-input-inline">
			        <input type="text" class="layui-input" name="${field.field}" id="${field.field}" placeholder="请输入${field.comment}"  style="width:150px">
		        </div>
#elseif(${field.matchType}=="dateRange")   
				<span class="search_title">${field.comment}：</span>
		        <div class="layui-input-inline">
		          <input name="beginTime_${field.field}" type="text" id="beginTime_${field.field}" class="layui-input" style="cursor: pointer" value="">
		         </div>
		          <span class="search_title">--</span>
		         <div class="layui-input-inline">
		          <input name="endTime_${field.field}" type="text" id="endTime_${field.field}" class="layui-input" style="cursor: pointer" value="">
		        </div>
#elseif(${field.matchType} == "select")
#if($field.inputValueMap)
				<div class="layui-input-inline">
					<label class="layui-form-label">${field.comment}</label>
					<div class="layui-input-block">
						<select name="${field.field}" id="${field.field}" class="xf_membill_selectAge" >
							<option value="">==请选择==</option>
#foreach($item in $field.inputValueMap.entrySet())
							<option value="$!{item.key}" >$!{item.value}</option>
#end
					   </select>
					</div>
				</div>
#elseif($field.inputType == "select"&&${field.inputValueTwo} != "")
				<div class="layui-input-inline">
					<label class="layui-form-label">${field.comment}</label>
					<div class="layui-input-block">
						<select id="${field.field}" name="${field.field}" class="xf_membill_selectAge" >
							<option value="">==请选择==</option>
							#{ list ${field.field}_list} 
							<option value="${ _?.id}" >${ _?.${field.inputValueTwo}}</option>
							#{/list}
					   </select>
				   </div>
				</div>
#else
				<div class="layui-input-inline">
					<label class="layui-form-label">${field.comment}</label>
					<div class="layui-input-block">
						<select name="${field.field}" id="${field.field}" class="xf_membill_selectAge" >
							<option value="">==请选择==</option>
					   </select>
					</div>
				</div>
#end
#end
#end
				 <input  type="hidden" id="orderType">
				 <input  type="hidden" id="orderfield">
				<a class="layui-btn search_btn" data-type="reload">搜索</a>
			</div>
			<div class="layui-inline">
			<button type="reset" class="layui-btn layui-btn-primary">清空</button>
			</div>
			<div class="layui-inline" style="float: right;margin-left: 10px">
			#{useroperation key:'${model.packageName}.${model.modulePackage}.${model.model}Action.deleteBatch',href:"#",show_value:"批量删除",class:'layui-btn layui-btn-danger layui-btn-normal delAll_btn'/}
			</div>
			<div class="layui-inline" style="float: right;margin-left: 10px">
			#{useroperation key:'${model.packageName}.${model.modulePackage}.${model.model}Action.add',href:"#",show_value:"添加",class:'layui-btn layui-btn-normal add_btn'/}
			</div>
		</form>
	</blockquote>
	<table id="list" lay-filter="list"></table>

	<!--操作-->
	<script type="text/html" id="listBar"> 
		#{useroperation key:'${model.packageName}.${model.modulePackage}.${model.model}Action.edit',href:"#",show_value:"编辑",class:'layui-btn layui-btn-xs',layevent:"edit"/}
		#{useroperation key:'${model.packageName}.${model.modulePackage}.${model.model}Action.delete',href:"#",show_value:"删除",class:'layui-btn layui-btn-xs layui-btn-danger',layevent:"del"/}
		#{useroperation key:'${model.packageName}.${model.modulePackage}.${model.model}Action.show',href:"#",show_value:"详情",class:'layui-btn layui-btn-xs layui-btn-primary',layevent:"look"/}
	</script>
#foreach($field in $fieldList)
#if($field.inputValueMap&&${field.inputType}=="select")	
	<script type="text/html" id="${field.field}_tmp">
#foreach($item in $field.inputValueMap.entrySet())
		{{# if(d.${field.columnName} == $item.key){ }}
		<span >$!{item.value}</span>
		{{#  }}}
#end
	</script>
#end
#if($field.inputValueMap&&${field.inputType}=="checkbox")	
	<script type="text/html" id="${field.field}_tmp">
		{{# var ${field.field}list = d.${field.field}.split(',') }}
		{{# for(var i=0;i<${field.field}list.length;i++){ }}
#foreach($item in $field.inputValueMap.entrySet())
		{{# if(${field.field}list[i] == $item.key){ }}
		<span >$!{item.value}</span>
		{{#  }}}
#end
		{{#  }}}
	</script>
#end
#end	
<script type="text/javascript">
 layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;
         function filterTime(val){
	        if(val < 10){
	            return "0" + val;
	        }else{
	            return val;
	        }
	    }
        var time = new Date();
#foreach($field in $fieldList)
#if(${field.matchType}=="dateRange")
		var ${field.field}Time = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate());
        var ${field.field}start = laydate.render({
	        elem: '#beginTime_${field.field}',
	        type: 'date',
	        trigger : "click",
	        done : function(value, date, endDate){
	            ${field.field}Time = value;
	            endMax = ${field.field}end.config.max;
                ${field.field}end.config.min = date;
                ${field.field}end.config.min.month = date.month -1;
	        }
	    });
        var ${field.field}end = laydate.render({
	        elem: '#endTime_${field.field}',
	        type: 'date',
	        trigger : "click",
	        done : function(value, date, endDate){
		        if($.trim(value) == ''){
                   var curDate = new Date();
                   date = {'date': curDate.getDate(), 'month': curDate.getMonth()+1, 'year': curDate.getFullYear()};
	            }
                ${field.field}start.config.max = date;
                ${field.field}start.config.max.month = date.month -1;
	            ${field.field}Time = value;
	        }
	    });
#end
#end
    //列表
    var tableIns = table.render({
        elem: '#list',
        url : '@{listJson()}',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 20,
        limits : [20,50,100,200,500,1000],
        id : "listTable",
        cols : [[
            {type: "checkbox", fixed:"left", width:50},
#foreach($field in $fieldList)
#if($field.listShow == true)
#if(${field.inputType}=="select"&&${field.inputValueTwo} != "")
			{field: '${field.columnName}_name', title: '${field.comment}', align:"center"},
#elseif($field.inputValueMap)
			{field: '${field.columnName}', title: '${field.comment}',templet:'#${field.field}_tmp', align:"center"},
#elseif(${field.inputType}=="datetime")
			{field: '${field.columnName}', title: '${field.comment}', width:180, align:"center", templet:function(d){
				if(d.${field.columnName}!=null)　
					return new Date(d.${field.columnName}).format('yyyy-MM-dd hh:mm:ss');
				else
					return "";
				
            }},
#elseif(${field.inputType}=="date")
			{field: '${field.columnName}', title: '${field.comment}', align:"center", templet:function(d){
			　　if(d.${field.columnName}!=null)
					return new Date(d.${field.columnName}).format('yyyy-MM-dd');
				else
					return "";
            }},
#else
        	{field: '${field.columnName}', title: '${field.comment}',  align:"center"},
#end
#end
#end
            {title: '操作', width:170, templet:'#listBar',fixed:"right",align:"center"}
        ]]
    });
    //实现整体排序，而不是单页排序
	table.on('sort(list)',function (obj) {  
		$("#orderfield").val(obj.field);
		$("#orderType").val(obj.type);
		$(".search_btn").click();
        return false;
	 });
	    
	 //搜索框回车事件
      $('.layui-form').on('keydown', function (event) {
          if (event.keyCode == 13) {
               
              $(".search_btn").click();
              return false
          }
      });
	//搜索
    $(".search_btn").on("click",function(){
          table.reload("listTable",{
              page: {
                  curr: 1 //重新从第 1 页开始
              },
              where: {
#foreach( $field in $fieldList )
#if(${field.matchType}=="any"||${field.matchType}=="eq"||${field.matchType}=="left"||${field.matchType}=="right")
					'${field.field}': $("#${field.field}").val(),  //${field.comment}
#elseif(${field.matchType}=="dateRange")   
					'beginTime_${field.field}': $("#beginTime_${field.field}").val(),  //开始${field.comment}
					'endTime_${field.field}': $("#endTime_${field.field}").val(),  //结束${field.comment}
#elseif(${field.matchType} == "select")
#if($field.inputType == "select"&&${field.inputValueTwo} != "")
					'${field.field}': $("#${field.field}").val(),  //${field.comment}
#else
					'${field.field}': $("#${field.field}").val(),  //${field.comment}
#end
#end
#end
					 orderTypeStr: $("#orderfield").val()+" "+$("#orderType").val()
                }
            })
    });

    //添加${model.comment}
    function addEditPage(edit){
    
    var url = "@{addPage()}";
     if(edit){
    	url = "@{editPage()}";
     }
    
        var index = layui.layer.open({
            title : "添加${model.comment}",
            type : 2,
            area : ["80%","80%"],
            content : url+"?sign="+edit,
            success : function(layero, index){}
        })
//         layui.layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
//         $(window).on("resize",function(){
//             layui.layer.full(index);
//         })
    }
    
    $(".add_btn").click(function(){
        addEditPage();
    })

    //批量删除${model.comment}
    $(".delAll_btn").click(function(){
        var checkStatus = table.checkStatus('listTable'),
             data = checkStatus.data,
            ids = [];
        if(data.length > 0) {
             for (var i=0;i<data.length;i++) {
                ids.push(data[i].id);
            }
            layer.confirm('确定删除选中的记录？', {icon: 3, title: '提示信息'}, function (index) {
               $.post("@{deleteBatch()}",{
                    ids : ids.join(',')  //将需要删除的newsId作为参数传入
                },function(data){
                tableIns.reload();
                layer.close(index);
                 })
            })
        }else{
            layer.msg("请选择需要删除的记录");
        }
    })

    //列表操作
    table.on('tool(list)', function(obj){
        var layEvent = obj.event,
            data = obj.data;
        if(layEvent === 'edit'){ //编辑
            addEditPage(data.id);
        } else if(layEvent === 'del'){ //删除
            layer.confirm('确定删除此记录？',{icon:3, title:'提示信息'},function(index){
                 $.post("@{delete()}",{
                     sign : data.id  //将需要删除的id作为参数传入
                 },function(data){
                    tableIns.reload();
                    layer.close(index);
                 })
            });
        } else if(layEvent === 'look'){ //预览
             
          var index = layui.layer.open({
            title : "详情",
            type : 2,
            content : "@{show()}?sign="+data.id,
            success : function(layero, index){}
        })
        layui.layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize",function(){
            layui.layer.full(index);
        })
        }
    });

})
 
</script>
